#!/bin/bash

DIR=/var/www/html/centos7-base
DIR2=/etc/yum.repos.d
DIR3=/media/cdrom
umount /dev/sr0
[ -d $DIR3 ] || mkdir -p /media/cdrom &>/dev/null
echo "/media/cdrom is already make!"
mount /dev/sr0 $DIR3 &>/dev/null
[ -d $DIR2/bak ] || mkdir -p $DIR2/bak &>/dev/null
mv $DIR2/C*.repo $DIR2/bak &>/dev/null
[ -f $DIR2/local.repo ] || echo -e "[local]\nname=local\nbaseurl=file:///media/cdrom\nenable=1\ngpgcheck=0" >$DIR2/local.repo
yum clean all &>/dev/null
yum makecache &>/dev/null
echo "已构建本地源"
read -p "请输入http服务器的IP:" IP
rpm -qa|grep httpd &>/dev/null
[ $? -ne 0 ] && yum -y install httpd  &>/dev/null
systemctl start httpd &>/dev/null && systemctl enable httpd &>/dev/null
if [ $? -eq 0 ]
then
        [ -d $DIR ] || mkdir -p $DIR &>/dev/null
        echo "make /var/www/html/centos7-base"
        cp -rf /media/cdrom/* $DIR &>/dev/null
        echo "copy finish"
else
        echo "WARNING:link cdrom!!!"
        exit
fi
#[ -d $DIR2/bak ] || mkdir -p $DIR2/bak &>/dev/null
#mv $DIR2/C*.repo $DIR2/bak &>/dev/null
echo -e "[http]\nname=http\nbaseurl=http://$IP/centos7-base\nenable=1\ngpgcheck=0" >$DIR2/http.repo
yum clean all &>/dev/null
yum makecache &>/dev/null
echo "http YUM reposity make successfully!"